<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace longbingcore\permissions;
class AdminMenu
{
    public static function all($uniacid)
    {
        $menu_data = longbing_init_info_data("AdminMenu", "model");
        $denyAdminMenuKeys = self::getAuthList($uniacid);
        $rst = [];
        foreach ($menu_data as $k => $menu) {
            if (array_key_exists($k, $denyAdminMenuKeys)) {
                if ($k == "appstore") {
                    $appMenudataList = longbing_init_info_data("AdminMenu", "app");
                    $app = json_decode($menu, true);
                    $children = $app["children"];
                    foreach ($appMenudataList as $appKey => $appMenu) {
                        if (array_key_exists($appKey, $denyAdminMenuKeys)) {
                            $m = json_decode($appMenu, true);
                            if (!empty($m)) {
                                foreach ($m as $item) {
                                    $children[] = $item;
                                }
                            }
                        }
                    }
                    $app["children"] = $children;
                    $rst[] = $app;
                } elseif ($k == "admin") {
                    $adminMenu = json_decode($menu, true);
                    $permission = new \app\admin\info\PermissionAdmin($uniacid);
                    $pAuthConfig = $permission->getPAuthConfig();
                    if ($pAuthConfig && $pAuthConfig["copyright_id"] != 0) {
                        $children = $adminMenu["children"];
                        foreach ($children as $k => $child) {
                            if ($child["path"] == "copyright") {
                                unset($children[$k]);
                            }
                        }
                        $adminMenu["children"] = array_values($children);
                        $url = $adminMenu["meta"]["subNavName"][1]["url"];
                        unset($url[0]);
                        $adminMenu["meta"]["subNavName"][1]["url"] = array_values($url);
                    }
                    $rst[] = $adminMenu;
                } else {
                    $rst[] = json_decode($menu, true);
                }
            }
        }
        return $rst;
    }

    public static function getAuthList($uniacid, $arr = [])
    {
        $denyAdminMenuKeys = [];
        if (empty($uniacid)) {
            return $denyAdminMenuKeys;
        }
        $adminModelListInfo = config("app.AdminModelList");
        $saas_auth_admin_model_list = $adminModelListInfo["saas_auth_admin_model_list"];
//        print_r($saas_auth_admin_model_list);
        if (!empty($saas_auth_admin_model_list)) {
            foreach ($saas_auth_admin_model_list as $key => $item) {
                if (!empty($arr) && !in_array($key, $arr)) {
                } else {
                    $className = "Permission" . ucfirst($key);
                    $permissionPath = APP_PATH . $key . "/info/" . $className . ".php";
                    if (file_exists($permissionPath) && (require_once $permissionPath)) {
                        $permissionClassName = "app\\" . $key . "\\info\\" . $className;
                        $permission = new $permissionClassName($uniacid, $item);
                        $denyAdminMenuKeys[$key] = $permission->pAuth();
                    }
                }
            }
        }
        return $denyAdminMenuKeys;
    }

    public static function getAppstoreInfoList($uniacid)
    {
        $dataList = longbing_init_info_data("Info", "app");
        $denyAdminMenuKeys = self::getAuthList($uniacid);
        $returnList = [];
        foreach ($dataList as $key => $item) {
            if (array_key_exists($item["name"], $denyAdminMenuKeys)) {
                $returnList[] = $item;
            }
        }
        return $returnList;
    }
}

?>